<%@ page import="cc.lucien.web.entity.User" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/6/4
  Time: 14:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        div{
            text-align: center;
        }
        a{
            color: #0000ff;
            text-decoration: none;
            cursor: pointer;
        }
        table{
            margin-left: 200px;
        }
        table tr th,table tr td{
            border: 1px solid coral;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <table>
            <caption> <h3>用户信息列表</h3> </caption>
            <tr>
                <td colspan="4"></td>
                <td> <a href="<%=application.getContextPath()%>/pages/add.jsp">添加</a></td>
            </tr>
            <tr>
                <th>ID</th>
                <th>用户名称</th>
                <th>用户账号</th>
                <th>电话</th>
                <th>操作</th>
            </tr>
            <%
                List<User> list = (List<User>) request.getAttribute("userList");
                for (User user : list ){
                %>
            <tr>
                <td><%=user.getId()%></td>
                <td><%=user.getName()%></td>
                <td><%=user.getUsername()%></td>
                <td><%=user.getTel()%></td>
                <td>
                    <button onclick="toUpdate(<%=user.getId()%>)">修改</button>
                    <button onclick="toDelete(<%=user.getId()%>)">删除</button>
                </td>
            </tr>
                <%
                }
            %>

        </table>
    </div>
</body>

    <script>

        <%--  修改的交互      --%>
        function toUpdate(id) {
            let flag = confirm("确定要修改吗？");
            if (flag) {
                window.location.href = "http://localhost:8080/webDemo02/web/user.do?method=queryById&id="+id;
            }
        }

        <%--   删除的交互     --%>
        function toDelete(id) {
            let flag = confirm("确定要删除此用户吗？");
            if (flag) {
                window.location.href = "http://localhost:8080/webDemo02/web/user.do?method=deleteById&id="+id;
            }
        }
    </script>
</html>
